/*
Copyright [2012] [Maria Eugenia Malagamba]
Copyright [2012] [Leandro Pellegrino]
Copyright [2012] [Julia Gambuzzi]
Copyright [2012] [Ignacio Capodanno]

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/

#pragma once
#include "FiguraPositiva.hpp"
#include "Coordenada.hpp"

class Rectangulo : public FiguraPositiva
{

public:

	// Rectangulos:
	// x,y------------------x+ancho,y
	// |					    	|
	// x,y+alto--------x+ancho,y+alto
	Rectangulo() : FiguraPositiva(){}
	Rectangulo(double x, double y, double ancho, double alto)
		: FiguraPositiva(x, y, ancho, alto){	}

	// Colision a nivel contorno (bounding box)
	// Hay intersección si uno de ellos superpone a otro
	virtual bool hayIntereseccion(Rectangulo *otroRectangulo){

		bool xOverlap = valueInRange(this->getX(), otroRectangulo->getX(), otroRectangulo->getLadoDerecho()) || 
						valueInRange(otroRectangulo->getX(), this->getX(), this->getLadoDerecho());

		bool yOverlap = valueInRange(this->getY(), otroRectangulo->getY(), otroRectangulo->getPiso()) || 
						valueInRange(otroRectangulo->getY(), this->getY(), this->getPiso());

		return xOverlap && yOverlap;
	}

	double getTecho() { return this->getY(); }
	double getPiso() { return this->getY() + this->getAlto(); }
	double getLadoIzquierdo() { return this->getX(); }
	double getLadoDerecho() { return this->getX() + this->getAncho(); }

	bool valueInRange(int value, int min, int max){ 
		return (value >= min) && (value <= max); 
	}

	virtual ~Rectangulo(){
	}
};
